﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using IntegrationTest.Properties;

namespace Test
{
    public partial class FormSetting : Form
    {
        public FormSetting()
        {
            InitializeComponent();
        }

        private void FormSetting_Load(object sender, EventArgs e)
        {
            this.labBack.BackColor = Settings.Default.BackColor;
            this.labLine.BackColor = Settings.Default.LineColor;
            this.labCenter.BackColor = Settings.Default.CenterLineColor;
            this.labFont.BackColor = Settings.Default.FontColor;
            this.labWave.BackColor = Settings.Default.WaveColor;
            this.numDisplaytime.Value = Settings.Default.WaveDisplayTime;
            this.numPt.Value = Settings.Default.MaxPtCount;
            this.numMax.Value = Settings.Default.Max;
            this.numCount.Value = Settings.Default.BoxCount;
            this.txtBoxNo.Text = Settings.Default.BoxNo;

            this.labBack.Click += labBack_Click;
            this.labLine.Click += labBack_Click;
            this.labCenter.Click += labBack_Click;
            this.labFont.Click += labBack_Click;
            this.labWave.Click += labBack_Click;
            this.radNot.Checked = !Settings.Default.IsProgram;
            this.radDo.Checked = Settings.Default.IsProgram;
        }

        private void labBack_Click(object sender, EventArgs e)
        {
            ColorDialog cd = new ColorDialog();
            if (DialogResult.OK == cd.ShowDialog())
            {
                ((Control)sender).BackColor = cd.Color;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Settings.Default.BackColor = this.labBack.BackColor;
            Settings.Default.LineColor = this.labLine.BackColor;
            Settings.Default.CenterLineColor = this.labCenter.BackColor;
            Settings.Default.FontColor = this.labFont.BackColor;
            Settings.Default.WaveColor = this.labWave.BackColor;
            Settings.Default.WaveDisplayTime = (int)this.numDisplaytime.Value;
            Settings.Default.MaxPtCount = (int)this.numPt.Value;
            Settings.Default.Max = (int)this.numMax.Value;
            Settings.Default.IsProgram = this.radDo.Checked;
            Settings.Default.BoxCount = (int)this.numCount.Value;
            Settings.Default.BoxNo = this.txtBoxNo.Text;
            Settings.Default.Save();
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Settings.Default.AllCount = 0;
            Settings.Default.PassCount = 0;
            Settings.Default.ErrorCount = 0;
            Settings.Default.ErrMacs = string.Empty;
            Settings.Default.Save();
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            Settings.Default.ErrMacs = "";
            Settings.Default.OkMacs = "";
            Settings.Default.Save();
        }
    }
}
